import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		zt_c: '#CC0200', //主题颜色
		status_code: 200, //成功状态码
		userInfo: uni.getStorageSync('userInfo'), //用户信息
		token: uni.getStorageSync('token'), //登录凭证
		tokena: uni.getStorageSync('tokena'), //临时登录凭证
		language: uni.getStorageSync('language') ? uni.getStorageSync('language') : 'zh', //中英文切换
		navh: uni.getStorageSync('navh') ? uni.getStorageSync('navh') : 64, //顶部导航栏高度
		btnh: uni.getStorageSync('btnh') ? uni.getStorageSync('btnh') : 34, //底部导航栏高度
		s_font: uni.getStorageSync('navh') ? uni.getStorageSync('navh') : '15px', //系统字体
		pid: uni.getStorageSync('pid') ? uni.getStorageSync('pid') : '', //上级用户id - 分享拉新
		address: '', //下单选择的地址
		coupon: '', //下单选择的优惠券
	},
	getters: {}, //vuex 计算属性
	mutations: {
		// 获取登录用户信息
		saveUserInfo(state, data) {
			state.userInfo = data
			uni.setStorageSync('userInfo', data)
		},
		// 获取登录token凭证
		saveToken(state, data) {
			state.token = data
			uni.setStorageSync('token', data)
		},
		// 获取登录临时tokena凭证
		saveTokena(state, data) {
			state.tokena = data
			uni.setStorageSync('tokena', data)
		},
		//保存切换语言标识
		saveLanguage(state, data) {
			state.language = data
			uni.setStorageSync('language', data)
		},
		//保存导航栏高度
		saveNavh(state, data) {
			state.navh = data
			uni.setStorageSync('navh', data)
		},
		//保存底部高度
		saveBtnh(state, data) {
			state.btnh = data
			uni.setStorageSync('btnh', data)
		},
		//系统字体
		saveSfont(state, data) {
			state.s_font = data
			uni.setStorageSync('s_font', data)
		},
		//保存上级id
		savePid(state, data) {
			state.pid = data
			uni.setStorageSync('pid', data)
		},

		//保存下单地址
		saveAddress(state, data) {
			state.address = data
		},
		//保存下单优惠券
		saveCoupon(state, data) {
			state.coupon = data
		},

		//退出登录  
		logout(state) {
			state.userInfo = ''
			state.token = ''
			state.pid = ''
			uni.removeStorageSync('userInfo')
			uni.removeStorageSync('token')
			uni.removeStorageSync('pid')
		},
		// 获取登录临时tokena凭证
		delTokena(state) {
			uni.removeStorageSync('tokena')
		},
		//删除上级id
		delPid(state, data) {
			state.pid = ''
			uni.removeStorageSync('pid')
		},
	},
	actions: {}
})
export default store